import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { title } from '@/settings'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页', icon: 'el-icon-s-home' }
      }
    ]
  },
  {
    path: '/assetManage',
    component: Layout,
    redirect: '/assetManage/fixedAsset',
    name: 'AssetManage',
    meta: {
      title: '资产管理',
      icon: 'el-icon-s-goods'
    },
    children: [
      {
        path: 'assetCategory',
        component: () => import('@/views/assetManage/assetCategory/index'), // Parent router-view
        name: 'AssetCategory',
        meta: { title: '资产分类' }
      },
      {
        path: 'assetCategory/add',
        component: () => import('@/views/assetManage/assetCategory/add/index'), // Parent router-view
        name: 'AssetCategoryAdd',
        meta: { title: '添加资产分类' },
        hidden: true
      },
      {
        path: 'assetCategory/edit/:id',
        component: () => import('@/views/assetManage/assetCategory/edit/index'), // Parent router-view
        name: 'assetCategoryEdit',
        meta: { title: '编辑资产分类' },
        hidden: true
      },
      {
        path: 'fixedAsset',
        component: () => import('@/views/assetManage/fixedAsset/index'), // Parent router-view
        name: 'FixedAsset',
        meta: { title: '固定资产' }
      },{
        path: 'fixedAsset/detail/:id',
        component: () => import('@/views/assetManage/fixedAsset/detail/index'), // Parent router-view
        name: 'FixedAssetDetail',
        meta: { title: '资产详情' },
        hidden: true
      },
      {
        path: 'fixedAsset/add',
        component: () => import('@/views/assetManage/fixedAsset/add/index'), // Parent router-view
        name: 'FixedAssetAdd',
        meta: { title: '添加固定资产' },
        hidden: true
      },
      {
        path: 'fixedAsset/edit/:id',
        component: () => import('@/views/assetManage/fixedAsset/edit/index'), // Parent router-view
        name: 'FixedAssetEdit',
        meta: { title: '编辑固定资产' },
        hidden: true
      },
      {
        path: 'intangibleAsset',
        redirect: '/assetManage/intangibleAsset/softwore',
        component: () => import('@/views/assetManage/intangibleAsset/index'), // Parent router-view
        name: 'IntangibleAsset',
        meta: { title: '无形资产' },
        children: [
          {
            path: 'software',
            component: () => import('@/views/assetManage/intangibleAsset/software/index'), // Parent router-view
            name: 'Software',
            meta: { title: '软件资产' }
          },
          {
            path: 'software/asset/detail/:id',
            component: () => import('@/views/assetManage/intangibleAsset/software/asset/detail/index'), // Parent router-view
            name: 'SoftwareDetail',
            meta: { title: '软件资产详情' },
            hidden: true
          },
          {
            path: 'software/asset/add',
            component: () => import('@/views/assetManage/intangibleAsset/software/asset/add/index'), // Parent router-view
            name: 'SoftwareAdd',
            meta: { title: '新增软件资产' },
            hidden: true
          },
          {
            path: 'software/asset/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/software/asset/edit/index'), // Parent router-view
            name: 'SoftwareEdit',
            meta: { title: '编辑软件资产' },
            hidden: true
          },
          {
            path: 'software/category/add',
            component: () => import('@/views/assetManage/intangibleAsset/software/category/add/index'), // Parent router-view
            name: 'SoftwareCategoryAdd',
            meta: { title: '新增软件资产类型' },
            hidden: true
          },
          {
            path: 'software/category/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/software/category/edit/index'), // Parent router-view
            name: 'SoftwareCategoryEdit',
            meta: { title: '编辑软件资产类型' },
            hidden: true
          },
          {
            path: 'copyright',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/index'), // Parent router-view
            name: 'Copyright',
            meta: { title: '著作权登记' }
          },
          {
            path: 'copyright/register/detail/:id',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/register/detail/index'), // Parent router-view
            name: 'CopyrightDetail',
            meta: { title: '著作权登记详情' },
            hidden: true
          },
          {
            path: 'copyright/register/add',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/register/add/index'), // Parent router-view
            name: 'CopyrightAdd',
            meta: { title: '新增著作权登记' },
            hidden: true
          },
          {
            path: 'copyright/register/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/register/edit/index'), // Parent router-view
            name: 'CopyrightEdit',
            meta: { title: '编辑著作权登记' },
            hidden: true
          },
          {
            path: 'copyright/opusCategory/add',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/opusCategory/add/index'), // Parent router-view
            name: 'OpusCategoryAdd',
            meta: { title: '新增著作类型' },
            hidden: true
          },
          {
            path: 'copyright/opusCategory/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/copyright/opusCategory/edit/index'), // Parent router-view
            name: 'OpusCategoryEdit',
            meta: { title: '编辑著作类型' },
            hidden: true
          },
          {
            path: 'patent',
            component: () => import('@/views/assetManage/intangibleAsset/patent/index'), // Parent router-view
            name: 'Patent',
            meta: { title: '专利权登记' }
          },
          {
            path: 'patent/register/detail/:id',
            component: () => import('@/views/assetManage/intangibleAsset/patent/register/detail/index'), // Parent router-view
            name: 'PatentDetail',
            meta: { title: '专利权登记详情' },
            hidden: true
          },
          {
            path: 'patent/register/add',
            component: () => import('@/views/assetManage/intangibleAsset/patent/register/add/index'),
            name: 'PatentAdd',
            meta: { title: '新增专利权登记' },
            hidden: true
          },
          {
            path: 'patent/register/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/patent/register/edit/index'), // Parent router-view
            name: 'PatentEdit',
            meta: { title: '编辑专利权登记' },
            hidden: true
          },
          {
            path: 'patent/patentCategory/add',
            component: () => import('@/views/assetManage/intangibleAsset/patent/patentCategory/add/index'),
            name: 'PatentCategoryAdd',
            meta: { title: '新增专利类型' },
            hidden: true
          },
          {
            path: 'patent/patentCategory/edit/:id',
            component: () => import('@/views/assetManage/intangibleAsset/patent/patentCategory/edit/index'), // Parent router-view
            name: 'PatentCategoryEdit',
            meta: { title: '编辑专利类型' },
            hidden: true
          }
        ]
      },
      {
        path: 'location',
        component: () => import('@/views/assetManage/location/index'), // Parent router-view
        name: 'Location',
        meta: { title: '存放位置' }
      },
      {
        path: 'storage',
        component: () => import('@/views/assetManage/storage/index'), // Parent router-view
        name: 'Storage',
        meta: { title: '仓库' }
      }

    ]
  },
  {
    path: '/accountManage',
    component: Layout,
    redirect: '/accountManage/account',
    name: 'AccountManage',
    meta: {
      title: '财务管理',
      icon: 'el-icon-data-line'
    },
    children: [
      {
        path: 'account',
        component: () => import('@/views/accountManage/account/index'), // Parent router-view
        name: 'Account',
        meta: { title: '资产入账' }
      },
      {
        path: 'depreciatedTask',
        component: () => import('@/views/accountManage/depreciatedTask/index'), // Parent router-view
        name: 'DepreciatedTask',
        meta: { title: '计提折旧' }
      },
      {
        path: 'depreciation',
        component: () => import('@/views/accountManage/depreciation/index'), // Parent router-view
        name: 'Depreciation',
        meta: { title: '折旧明细' }
      }

    ]
  },
  {
    path: '/item',
    component: Layout,
    redirect: '/item/catalog',
    name: 'Item',
    meta: {
      title: '物品管理',
      icon: 'el-icon-collection'
    },
    children: [
      {
        path: 'catalog',
        component: () => import('@/views/item/catalog/index'), // Parent router-view
        name: 'Catalog',
        meta: { title: '物品档案' }
      },
      {
        path: 'type',
        component: () => import('@/views/item/type/index'), // Parent router-view
        name: 'Type',
        meta: { title: '物品分类' }
      }

    ]
  },
  {
    path: '/mainten',
    component: Layout,
    redirect: '/mainten/report',
    name: 'Mainten',
    meta: {
      title: '维保管理',
      icon: 'el-icon-cpu'
    },
    children: [
      {
        path: 'report',
        component: () => import('@/views/mainten/report/index'), // Parent router-view
        name: 'Report',
        meta: { title: '资产报修' }
      },
      {
        path: 'report/add',
        name:'ReportAdd',
        component: () => import('@/views/mainten/report/add'),
        hidden: true,
        meta: { title: '新增报修' }
      },
      {
        path: 'report/edit',
        name: 'ReportEdit',
        component: () => import('@/views/mainten/report/edit'),
        hidden: true,
        meta: { title: '编辑报修'}
      },
      {
        path: 'repairRecord',
        component: () => import('@/views/mainten/repairRecord/index'), // Parent router-view
        name: 'RepairRecord',
        meta: { title: '维修记录' }
      },
      {
        path: 'repairRecord/add',
        name: 'RepairRecordAdd',
        component: () => import('@/views/mainten/repairRecord/add'),
        hidden: true,
        meta: { title: '新增记录' }
      },
      {
        path: 'repairRecord/edit',
        name: 'RepairRecordEdit',
        component: () => import('@/views/mainten/repairRecord/edit'),
        hidden: true,
        meta: { title: '编辑记录' }
      },
      {
        path: 'maintenApply',
        component: () => import('@/views/mainten/maintenApply/index'), // Parent router-view
        name: 'MaintenApply',
        meta: { title: '维保申请' }
      },
      {
        path: 'maintenRecord',
        component: () => import('@/views/mainten/maintenRecord/index'), // Parent router-view
        name: 'MaintenRecord',
        meta: { title: '维保记录' }
      },
      {
        path: 'maintenVendor',
        redirect: '/mainten/maintenVendor/vendor',
        component: () => import('@/views/mainten/maintenVendor/index'),
        name: 'MaintenVendor',
        meta: { title: '维保商管理' },
        children: [
          {
            path: 'vendor',
            component: () => import('@/views/mainten/maintenVendor/vendor/index'), // Parent router-view
            name: 'Vendor',
            meta: { title: '维保商' }
          },
          {
            path: 'personal',
            component: () => import('@/views/mainten/maintenVendor/personal/index'), // Parent router-view
            name: 'Personal',
            meta: { title: '维保商人员' }
          }

        ]
      }

    ]
  },
  {
    path: '/assetUse',
    redirect: '/assetUse/claim',
    component: Layout,
    name: 'AssetUse',
    meta: {
      title: '资产使用',
      icon: 'el-icon-stopwatch'
    },
    children: [
      {
      path: 'claim', // 父路由
      component: () => import('@/views/assetUse/claim/index'), // Parent router-view
      name: 'Claim',
      meta: { title: '资产申领' },
      }, 
      {
        path: '/claimAdd', // 子路由
        component: () => import('@/views/assetUse/claim/claimAdd.vue'),
        name: 'claimAdd',
        meta: { title: '资产申领添加' },
        hidden: true
      },
      {
        path: '/claimEdit', // 子路由
        component: () => import('@/views/assetUse/claim/claimEdit.vue'),
        name: 'claimEdit',
        meta: { title: '资产申领编辑' },
        hidden: true
      },
      {
        path: '/claimQuery', // 子路由
        component: () => import('@/views/assetUse/claim/claimQuery.vue'),
        name: 'claimQuery',
        meta: { title: '资产申领查看' },
        hidden: true
      }, 
      {
        path: 'borrow',
        component: () => import('@/views/assetUse/borrow/index'), // Parent router-view
        name: 'Borrow',
        meta: { title: '资产借用' }
      },
      {
        path: 'borrow/add',
        component: () => import('@/views/assetUse/borrow/add'), // Parent router-view
        name: 'borrowAddPage',
        hidden:true,
        meta: { title: '资产借用添加' }
      },
      {
        path: 'return',
        component: () => import('@/views/assetUse/return/index'), // Parent router-view
        name: 'Return',
        meta: { title: '资产归还' }
      },
      {
        path: 'return/add',
        component: () => import('@/views/assetUse/return/add'), // Parent router-view
        name: 'returnAddPage',
        hidden:true,
        meta: { title: '资产归还添加' }
      },
      {
        path: 'intoStorage',
        component: () => import('@/views/assetUse/intoStorage/index'), // Parent router-view
        name: 'IntoStorage',
        meta: { title: '资产入库' }
      },
      {
        path: 'intoStorage/add',
        component: () => import('@/views/assetUse/intoStorage/add'), // Parent router-view
        name: 'intoStorageAddPage',
        hidden:true,
        meta: { title: '资产出库添加' }
      },
      {
        path: 'outStorage',
        component: () => import('@/views/assetUse/outStorage/index'), // Parent router-view
        name: 'OutStorage',
        meta: { title: '资产出库' }
      },
      {
        path: 'outStorage/add',
        component: () => import('@/views/assetUse/outStorage/add'), // Parent router-view
        name: 'outStorageAddPage',
        hidden:true,
        meta: { title: '资产出库添加' }
      },
      {
        path: 'distribute',
        component: () => import('@/views/assetUse/distribute/index'), // Parent router-view
        name: 'Distribute',
        meta: { title: '资产派发' }
      },
      {
        path: '/distributeAdd', // 子路由
        component: () => import('@/views/assetUse/distribute/distributeAdd.vue'),
        name: 'distributeAdd',
        meta: { title: '资产派发添加' },
        hidden: true
      },
      {
        path: '/distributeEdit', // 子路由
        component: () => import('@/views/assetUse/distribute/distributeEdit.vue'),
        name: 'distributeEdit',
        meta: { title: '资产派发编辑' },
        hidden: true
      },
      {
        path: '/distributeQuery', // 子路由
        component: () => import('@/views/assetUse/distribute/distributeQuery.vue'),
        name: 'distributeQuery',
        meta: { title: '资产派发查看' },
        hidden: true
      },
      {
        path: 'dispose',
        component: () => import('@/views/assetUse/dispose/index'), // Parent router-view
        name: 'Dispose',
        meta: { title: '资产处置' }
      },
      {
        path: '/disposeAdd', // 子路由
        component: () => import('@/views/assetUse/dispose/disposeAdd.vue'),
        name: 'disposeAdd',
        meta: { title: '资产处置添加' },
        hidden: true
      },
      {
        path: '/disposeEdit', // 子路由
        component: () => import('@/views/assetUse/dispose/disposeEdit.vue'),
        name: 'disposeEdit',
        meta: { title: '资产处置编辑' },
        hidden: true
      },
      {
        path: '/disposeQuery', // 子路由
        component: () => import('@/views/assetUse/dispose/disposeQuery.vue'),
        name: 'disposeQuery',
        meta: { title: '资产处置查看' },
        hidden: true
      },
      {
        path: 'allocate',
        component: () => import('@/views/assetUse/allocate/index'), // Parent router-view
        name: 'Allocate',
        meta: { title: '资产调拨' }
      },
      {
        path: '/allocateAdd', // 子路由
        component: () => import('@/views/assetUse/allocate/allocateAdd.vue'),
        name: 'allocateAdd',
        meta: { title: '资产调拨添加' },
        hidden: true
      },
      {
        path: '/allocateEdit', // 子路由
        component: () => import('@/views/assetUse/allocate/allocateEdit.vue'),
        name: 'allocateEdit',
        meta: { title: '资产调拨编辑' },
        hidden: true
      },
      {
        path: '/allocateQuery', // 子路由
        component: () => import('@/views/assetUse/allocate/allocateQuery.vue'),
        name: 'allocateQuery',
        meta: { title: '资产调拨查看' },
        hidden: true
      }
    ]
  },
  {
    path: '/assetBuy',
    component: Layout,
    redirect: '/assetBuy/order',
    name: 'AssetBuy',
    meta: {
      title: '资产采购',
      icon: 'el-icon-s-order'
    },
    children: [
      {
        path: 'order',
        component: () => import('@/views/assetBuy/order/index'), // Parent router-view
        name: 'Order',
        meta: { title: '采购订单' }
      },
      {
        path: 'accept',
        component: () => import('@/views/assetBuy/accept/index'), // Parent router-view
        name: 'Accept',
        meta: { title: '采购验收' }
      },
      {
        path: 'supplierManage',
        redirect: '/assetBuy/supplierManage/supplier',
        component: () => import('@/views/assetBuy/supplierManage/index'),
        name: 'supplierManage',
        meta: { title: '供应商管理' },
        children: [
          {
            path: 'supplier',
            component: () => import('@/views/assetBuy/supplierManage/supplier/index'), // Parent router-view
            name: 'Supplier',
            meta: { title: '供应商' }
          },
          {
            path: 'personnel',
            component: () => import('@/views/assetBuy/supplierManage/personnel/index'), // Parent router-view
            name: 'personnel',
            meta: { title: '供应商人员' }
          }
        ]
      }
    ]
  },
  {
    path: '/assetInventory',
    component: Layout,
    redirect: '/assetInventory',
    children: [
      {
        path: '/assetInventory',
        component: () => import('@/views/assetInventory/index'),
        name: 'AssetInventory',
        meta: {
          title: '资产盘点',
          icon: 'el-icon-data-analysis'
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/depart',
    name: 'System',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools'
    },
    children: [
      {
        path: 'depart',
        component: () => import('@/views/system/depart/index'), // Parent router-view
        name: 'Depart',
        meta: { title: '部门管理' }
      },
      {
        path: 'permission',
        component: () => import('@/views/system/permission/index'), // Parent router-view
        name: 'Permission',
        meta: { title: '权限管理' }
      },
      {
        path: 'position',
        component: () => import('@/views/system/position/index'), // Parent router-view
        name: 'Position',
        meta: { title: '岗位管理' }
      },
      {
        path: 'role',
        component: () => import('@/views/system/role/index'), // Parent router-view
        name: 'Role',
        meta: { title: '角色管理' }
      },
      {
        path: 'user',
        component: () => import('@/views/system/user/index'), // Parent router-view
        name: 'User',
        meta: { title: '用户管理' }
      }

    ]
  },
  {
    path: '/personalCenter',
    component: Layout,
    redirect: '/personalCenter/myInfo',
    name: 'PersonalCenter',
    meta: {
      title: '个人中心',
      icon: 'el-icon-user-solid'
    },
    children: [
      {
        path: 'myInfo',
        component: () => import('@/views/personalCenter/myInfo/index'), // Parent router-view
        name: 'MyInfo',
        meta: { title: '个人信息' }
      },
      {
        path: 'myAsset',
        component: () => import('@/views/personalCenter/myAsset/index'), // Parent router-view
        name: 'MyAsset',
        meta: { title: '我的资产' }
      },
      {
        path: 'myInventory',
        component: () => import('@/views/personalCenter/myInventory/index'), // Parent router-view
        name: 'MyInventory',
        meta: { title: '我的盘点' }
      },
      {
        path: 'myMainten',
        component: () => import('@/views/personalCenter/myMainten/index'), // Parent router-view
        name: 'MyMainten',
        meta: { title: '我的维保记录' }
      },
      {
        path: 'myRepair',
        component: () => import('@/views/personalCenter/myRepair/index'), // Parent router-view
        name: 'MyRepair',
        meta: { title: '我的维修记录' }
      }

    ]
  },
  {
    path: '/announce',
    component: Layout,
    redirect: '/announce',
    children: [
      {
        path: '/announce',
        component: () => import('@/views/announce/index'), // Parent router-view
        name: 'Announce',
        meta: {
          title: '公告管理',
          icon: 'el-icon-s-promotion'
        }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
